package fun.werfamily.wf.order.core.controller;

import fun.werfamily.wf.base.vo.Result;
import fun.werfamily.wf.order.core.domain.dto.result.CartItemDTO;
import fun.werfamily.wf.order.core.domain.dto.result.OrderGoodsCartDTO;
import fun.werfamily.wf.order.core.domain.service.OrderGoodsCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Mr.WenMing Zhang
 * @Date: 2022-08-28 11:31
 * @Description:
 */

@Api(tags = "购物车模块")
@RequestMapping("/shopping/cart")
@RestController
public class OrderGoodsCartController {

    @Resource
    private OrderGoodsCartService cartService;

    @ApiOperation("购物车详情")
    @PostMapping("/item")
    public Result<OrderGoodsCartDTO> getGoodsCartItem() {
        return Result.success(cartService.getGoodsCartItem());
    }

    @ApiOperation("商品加入购物车")
    @PostMapping("/add")
    public Result<Boolean> addGoodsCartItem(@Validated @RequestBody CartItemDTO cartItemDTO) {
        return Result.success(cartService.addGoodsCartItem(cartItemDTO));
    }

    @ApiOperation("修改购物车商品数量")
    @PostMapping("/change")
    public Result<Boolean> updateGoodsCartItem(@Validated @RequestBody CartItemDTO cartItemDTO) {
        return Result.success(cartService.updateGoodsCartItem(cartItemDTO));
    }

    @ApiOperation("删除购物车商品")
    @PostMapping("/remove")
    public Result<Boolean> removeGoodsCartItem(@RequestBody List<String> skuCodes) {
        return Result.success(cartService.removeGoodsCartItem(skuCodes));
    }

    @ApiOperation("清空购物车商品")
    @PostMapping("/empty")
    public Result<Boolean> removeAllGoodsCartItem() {
        return Result.success(cartService.removeAllGoodsCartItem());
    }

    @ApiOperation("获取物车商品数量")
    @GetMapping("/num")
    public Result<Integer> getGoodsCartItemNum() {
        return Result.success(cartService.countCartItems());
    }
}
